1pub mod chat_history;
14pub mod download;
15pub mod download_event_emitter;
16pub mod download_manager;
17pub mod download_state;
18pub mod event_emitter;
19pub mod gguf_parser;
20pub mod huggingface;
21pub mod mcp_dto;
22pub mod mcp_error;
23pub mod mcp_repository;
24pub mod model_catalog;
25pub mod model_registrar;
26pub mod model_repository;
27pub mod model_runtime;
28pub mod process_runner;
29pub mod server_health;
30pub mod server_log_sink;
31pub mod settings_repository;
32pub mod system_probe;
33pub mod tool_support;
34
35use std::sync::Arc;
36use thiserror::Error;
37
38pub use chat_history::{ChatHistoryError, ChatHistoryRepository};
40pub use download::{QuantizationResolver, Resolution, ResolvedFile};
41pub use download_event_emitter::{AppEventBridge, DownloadEventEmitterPort, NoopDownloadEmitter};
42pub use download_manager::{DownloadManagerConfig, DownloadManagerPort, DownloadRequest};
43pub use download_state::DownloadStateRepositoryPort;
44pub use event_emitter::{AppEventEmitter, NoopEmitter};
45pub use gguf_parser::{
46 GgufCapabilities, GgufMetadata, GgufParseError, GgufParserPort, NoopGgufParser,
47};
48pub use huggingface::{
49 HfClientPort, HfFileInfo, HfPortError, HfQuantInfo, HfRepoInfo, HfSearchOptions, HfSearchResult,
50};
51pub use mcp_dto::{ResolutionAttempt, ResolutionStatus};
52pub use mcp_error::{McpErrorCategory, McpErrorInfo, McpServiceError};
53pub use mcp_repository::{McpRepositoryError, McpServerRepository};
54pub use model_catalog::{CatalogError, ModelCatalogPort, ModelLaunchSpec, ModelSummary};
55pub use model_registrar::{CompletedDownload, ModelRegistrarPort};
56pub use model_repository::ModelRepository;
57pub use model_runtime::{ModelRuntimeError, ModelRuntimePort, RunningTarget};
58pub use process_runner::{ProcessHandle, ProcessRunner, ServerConfig, ServerHealth};
59pub use server_health::ServerHealthStatus;
60pub use server_log_sink::ServerLogSinkPort;
61pub use settings_repository::SettingsRepository;
62pub use system_probe::{SystemProbeError, SystemProbePort, SystemProbeResult};
63pub use tool_support::{
64 ModelSource, ToolFormat, ToolSupportDetection, ToolSupportDetectionInput,
65 ToolSupportDetectorPort,
66};
67
68#[derive(Clone)]
85pub struct Repos {
86 pub models: Arc<dyn ModelRepository>,
88 pub settings: Arc<dyn SettingsRepository>,
90 pub mcp_servers: Arc<dyn McpServerRepository>,
92 pub chat_history: Arc<dyn ChatHistoryRepository>,
94}
95
96impl Repos {
97 pub fn new(
99 models: Arc<dyn ModelRepository>,
100 settings: Arc<dyn SettingsRepository>,
101 mcp_servers: Arc<dyn McpServerRepository>,
102 chat_history: Arc<dyn ChatHistoryRepository>,
103 ) -> Self {
104 Self {
105 models,
106 settings,
107 mcp_servers,
108 chat_history,
109 }
110 }
111}
112
113#[derive(Debug, Error)]
118pub enum RepositoryError {
119 #[error("Not found: {0}")]
121 NotFound(String),
122
123 #[error("Already exists: {0}")]
125 AlreadyExists(String),
126
127 #[error("Storage error: {0}")]
129 Storage(String),
130
131 #[error("Serialization error: {0}")]
133 Serialization(String),
134
135 #[error("Constraint violation: {0}")]
137 Constraint(String),
138}
139
140#[derive(Debug, Error)]
145pub enum ProcessError {
146 #[error("Failed to start: {0}")]
148 StartFailed(String),
149
150 #[error("Failed to stop: {0}")]
152 StopFailed(String),
153
154 #[error("Process not running: {0}")]
156 NotRunning(String),
157
158 #[error("Health check failed: {0}")]
160 HealthCheckFailed(String),
161
162 #[error("Configuration error: {0}")]
164 Configuration(String),
165
166 #[error("Resource exhaustion: {0}")]
168 ResourceExhausted(String),
169
170 #[error("Internal error: {0}")]
172 Internal(String),
173}
174
175#[derive(Debug, Error)]
181pub enum CoreError {
182 #[error(transparent)]
184 Repository(#[from] RepositoryError),
185
186 #[error(transparent)]
188 Process(#[from] ProcessError),
189
190 #[error(transparent)]
192 Settings(#[from] crate::settings::SettingsError),
193
194 #[error("Validation error: {0}")]
196 Validation(String),
197
198 #[error("Configuration error: {0}")]
200 Configuration(String),
201
202 #[error("External service error: {0}")]
204 ExternalService(String),
205
206 #[error("Internal error: {0}")]
208 Internal(String),
209}